package com.dpteam.controller;

import com.dpteam.bean.MemberInfo;
import com.dpteam.bean.NoticeInfo;
import com.dpteam.bean.ProductInfo;
import com.dpteam.bean.UserInfo;
import com.dpteam.service.*;
import com.dpteam.util.Constant;
import com.dpteam.util.Page;
import com.dpteam.util.PageFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: luolei
 * Date: 2016/1/11
 * Time: 16:15
 */
@Controller
@RequestMapping("link")
public class LinkController {

    @Resource
    private MemberService memberService;

    @Resource
    private NewsService newsService;

    @Resource
    private UserManageService userManageService;

    @Resource
    private ProductService productService;

    @Resource
    private UserService userService;

    @RequestMapping("mainPage")
    public String mainPage() {
        return "mainPage";
    }

    @RequestMapping("checkOut")
    public String checkOut() {
        return "checkOut";
    }

    @RequestMapping("storageAdd")
    public String storageAdd() {
        return "storageAdd";
    }

    @RequestMapping("goods")
    public String goods() {
        return "goods";
    }

    @RequestMapping("storageSearch")
    public String storageSearch() {
        return "storageSearch";
    }

    @RequestMapping("notice")
    public String notice(@RequestParam(defaultValue = "1") int currentPage, ModelMap map) {
        Page page = PageFactory.getPage(currentPage);
        List<NoticeInfo> notices = newsService.findAll(page);
        map.put(Constant.notices, notices);
        map.put(Constant.page, page);
        return "notice";
    }

    @RequestMapping("memberSearch")
    public String memberSearch(ModelMap map,@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "10") int pageSize) {
        Page page = PageFactory.getPage(currentPage, pageSize);
        List<MemberInfo> memberInfos = memberService.findAll(page);
        map.put(Constant.page, page);
        map.put(Constant.members, memberInfos);
        return "memberSearch";
    }

    @RequestMapping("memberAdd")
    public String memberAdd(ModelMap map) {
        List<UserInfo> userInfos = userManageService.findAll();
        map.put(Constant.users, userInfos);
        return "memberAdd";
    }

    @RequestMapping("goodsSearch")
    public String goodsSearch(ModelMap map,@RequestParam(defaultValue = "1") int currentPage,@RequestParam(defaultValue = "10") int pageSize) {
        Page page = PageFactory.getPage(currentPage, pageSize);
        List<ProductInfo> products = productService.findAllProductPage(page);
        map.put(Constant.products, products);
        map.put(Constant.page, page);
        return "goodsSearch";
    }

    @RequestMapping("goodsReject")
    public String goodsReject() {
        return "goodsReject";
    }

    @RequestMapping("makeNotice")
    public String makeNotice() {
        return "makeNotice";
    }

    @RequestMapping("staffManage")
    public String staffManage() {
        return "staffManage";
    }

    @RequestMapping("showStorage")
    public String showStorage() {
        return "showStorage";
    }

    @RequestMapping("addUser")
    public String addUser() {
        return "addUser";
    }

    @RequestMapping("personDetails")
    public String personDetail() {
        return "personDetails";
    }
}
